package com.platform.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.sys.dao.PrjExamineAvoidDao;
import com.platform.modules.sys.entity.PrjExamineAvoidEntity;
import com.platform.modules.sys.service.PrjExamineAvoidService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 同体回避设置Service实现类
 *
 * @author 肖亮
 * @date 2019-07-12 11:29:56
 */
@Service("prjExamineAvoidService")
public class PrjExamineAvoidServiceImpl extends ServiceImpl<PrjExamineAvoidDao, PrjExamineAvoidEntity> implements PrjExamineAvoidService {

    @Override
    public List<PrjExamineAvoidEntity> queryAll(Map<String, Object> params) {
        return baseMapper.queryAll(params);
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.id");
        params.put("asc", false);
        Page<PrjExamineAvoidEntity> page = new Query<PrjExamineAvoidEntity>(params).getPage();
        return page.setRecords(baseMapper.selectPrjExamineAvoidPage(page, params));
    }

    
    
    @Override
    public boolean add(PrjExamineAvoidEntity prjExamineAvoid) {
    	//校验是否有这个关联关系
    	Map<String, Object> params=new HashMap<String, Object>();
    	params.put("drawingUnit", prjExamineAvoid.getDrawingUnit());
    	params.put("designUnit", prjExamineAvoid.getDesignUnit());
    	List<PrjExamineAvoidEntity> list=baseMapper.queryByDrawingAndDesign(params);
    	if(list==null||list.isEmpty()) {
    		return this.save(prjExamineAvoid);
    	}else{
    		return true;
    	}
    }

    @Override
    public boolean update(PrjExamineAvoidEntity prjExamineAvoid) {
        return this.updateById(prjExamineAvoid);
    }

    @Override
    public boolean delete(String id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(String[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }
}
